<?php
class ClassStudent extends AppModel {
	var $name = 'ClassStudent';
	var $validate = array(
		'name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Tên lớp không được rỗng',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'unique' => array( 
                'rule' => array('checkUnique', 'name'), 
                'message' => 'Tên lớp này đã tạo, hãy kiểm tra lại' 
             )
		),
		'active' => array(
			'boolean' => array(
				'rule' => array('boolean'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $hasMany = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'class_student_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
		function checkUnique($data, $fieldName) { 
            $valid = false; 
            if(isset($fieldName) && $this->hasField($fieldName)) { 
             $valid = $this->isUnique(array($fieldName => $data)); 
               } 
               return $valid;
	}
}
?>